<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ include file="/page/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@ include file="/adapter/adapter-easyui.jsp"%>
<%@ include file="/adapter/adapter-bootstrap.jsp"%>
<link
	href="${pageContext.request.contextPath}/frontframe/easyui/themes/easyui-extend.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript">

    var sroleid;
	function goBack() {
		//window.location.href='${ctx}/appFrameModule1/appFrameTradeMain?appid=${appid}'
		//window.history.back(-1);
		window.history.go(-2);
	}
	
	
    function clickRole(roleid){
    	//document.getElementById("operationsDiv").innerHtml="";
    	sroleid=roleid;
    	var operationsDiv=document.getElementById("operationsDiv");
    	//删除operationsDiv地下的所有的子节点
    	if(operationsDiv.hasChildNodes())
    	{
    		operationsDiv.childNodes[0].parentNode.removeChild(operationsDiv.childNodes[0]);
    	}

    	   $.ajax({
    	        url:"${ctx}/appMenuResource/queryMenu?roleid="+roleid+"&appid=${appid}",
    	        type: "POST",      
    	        dataType:"json",
    	        async: false,
    	        success: function(data) {
    	        	if(data.flag>0){
    		            alert("保存成功！");	
    		            //window.location.reload();
    	        	}
    				var op=document.createElement("DIV");
    		        $.each(data, function(index, element) {
    		        	var check = document.createElement("INPUT");
    		        	//alert(element.menuId+"///"+element.menuName+"///"+element.menuIcon);
    					check.id = element.menuId;
    					check.name = element.menuName;
    					check.type = "checkbox";
    					if("1"==element.menuIcon){
        					check.checked = true;	
    					}
    					check.onclick = Function("selectCheck(this,'"+element.menuId+"')");
    					var textNode = document.createTextNode(element.menuName);
    					var br=document.createElement("Br");
    					op.appendChild(check);
    					//op.appendChild("<Br>");
    					op.appendChild(textNode);
    					op.appendChild(br);
    	          }); 
    				operationsDiv.appendChild(op);
    	        },
    	        error: function() {
    	          alert("error");
    	        }
    	      });
    }
    
    
    function initRole(){
    	var operationsDiv=document.getElementById("operationsDiv");
    	//删除operationsDiv地下的所有的子节点
    	if(operationsDiv.hasChildNodes())
    	{
    		operationsDiv.childNodes[0].parentNode.removeChild(operationsDiv.childNodes[0]);
    	}

    	   $.ajax({
    	        url:"${ctx}/appMenuResource/queryMenu?roleid=-1&appid=${appid}",
    	        type: "POST",      
    	        dataType:"json",
    	        async: false,
    	        success: function(data) {
    	        	if(data.flag>0){
    		            alert("保存成功！");	
    	        	}
    				var op=document.createElement("DIV");
    		        $.each(data, function(index, element) {
    		        	var check = document.createElement("INPUT");
    					check.id = element.menuId;
    					check.name = element.menuName;
    					check.type = "checkbox";
    					if("1"==element.menuIcon){
        					check.checked = true;	
    					}
    					check.onclick = Function("selectCheck(this,'"+element.menuId+"')");
    					var textNode = document.createTextNode(element.menuName);
    					var br=document.createElement("Br");
    					op.appendChild(check);
    					op.appendChild(textNode);
    					op.appendChild(br);
    	          }); 
    				operationsDiv.appendChild(op);
    	        },
    	        error: function() {
    	          alert("error");
    	        }
    	      });
    }
    
    function save(){
    	var operStr="";
		var operationDiv = document.getElementById("operationsDiv");
		var operList = operationDiv.getElementsByTagName("input");
		for(var k=0;k<operList.length;k++){
			if(operList[k].type == "checkbox"){
				if(operList[k].checked){
					operStr=operStr+operList[k].id+",";
					//selectCount++;
				}
			}
		}
		
		if(operStr.indexOf(",") >= 0){
			operStr=operStr.substring(0,operStr.length-1);
		}
		
		
 	   $.ajax({
	        url:"${ctx}/appMenuResource/saveRoleMenu?roleid="+sroleid+"&appid=${appid}&menuStr="+operStr,
	        type: "POST",      
	        dataType:"json",
	        async: false,
	        success: function(data) {
	        	if(data.flag>0){
		            alert("保存成功！");	
		            //window.location.reload();
	        	}
	        },
	        error: function() {
	          alert("error");
	        }
	      });
		
		
    }
</script>
</head>
<body  onload="initRole()">  
	<!--      <div class="panel panel-default">
	   <div class="panel-heading">
	      <h3 class="panel-title">
	                                   修改用户信息
	      </h3>
	   </div>
	   <div class="panel-body"> -->
	<!-- 开始 -->
	<table id="whole">
<!-- 		<tr height="23" bgcolor='#E8F2FE' valign="middle">
			<td align="center">角色列表</td>
			<td>可授菜单</td>
		</tr> -->
		<tr>
			<td style="width: 350px;height:500px border-right-width: 1px;border: solid;border-color: white;border-style: solid;">
				<div id="roleList"   style="width: 350px;height:400px;padding-left: 20px">
							<div id="p" class="easyui-panel"  style="width:100%;height:100%;padding:10px;" title="角色列表">
					<UL style="list-style-type:none">
		<%-- 				<c:forEach items="${context['SRoleList']}" var="role">
							<LI style="width: 240"><A style="width: 230"
								id="${role.roleno}" onclick="clickRole(this)">${role.rolename}</A>
							</LI> --%>
							<c:forEach items="${arList}" var="role">
							<li style="list-style-type:none">
							<A style="width: 230;text-decoration:none" id="${role.appRoleId}" onclick="clickRole('${role.appRoleId}')">${role.appRoleName}</A>
							</li>
							</c:forEach>
<%--							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
							<li>菜单一</li>
 						</c:forEach> --%>
					</UL>
					</div>
				</div>
			</td>

			<td  style="width: 350px;height:500px border-right-width: 1px;border: solid;border-color: white;border-style: solid;">
				<div id=""  style="padding-left: 20px;width: 350px;height:400px">
							<div id="operationsDiv" class="easyui-panel" style="width:100%;height:100%;padding:10px;" title="可授菜单">
<!-- 				<input  type="checkbox" value=""  />&nbsp;&nbsp;菜单一</br>
				<input  type="checkbox" value=""  />&nbsp;&nbsp;菜单一</br>
				<input  type="checkbox" value=""  />&nbsp;&nbsp;菜单一</br>
				<input  type="checkbox" value=""  />&nbsp;&nbsp;菜单一</br>
				<input  type="checkbox" value=""  />&nbsp;&nbsp;菜单一</br>
				<input  type="checkbox" value=""  />&nbsp;&nbsp;菜单一</br>
				<input  type="checkbox" value=""  />&nbsp;&nbsp;菜单一</br> -->
							</div>
				</div> <br>
				<button type="button" id="save_button" onclick="save()">保存</button>
				
			</td>
		</tr>
	</table>

	<!-- 结束 -->
	<!-- 	   </div>
	</div> -->

</body>
</html>
